package com.chlitina.store.modules.cash.model;

import java.util.ArrayList;
import java.util.List;

import com.chlitina.store.common.utils.StoreCareUtils;
import com.chlitina.store.common.utils.Utils;
import com.chlitina.store.modules.base.entity.Customer;
import com.chlitina.store.modules.base.entity.CustomerEmployeeRelationship;
import com.chlitina.store.modules.base.entity.StoreCardTemplateDuration;
import com.chlitina.store.modules.base.entity.StoreCardTemplateTimes;
import com.chlitina.store.modules.base.entity.StoreCare;
import com.chlitina.store.modules.cash.entity.StoreCardAll;
import com.chlitina.store.modules.cash.entity.StoreCardDuration;
import com.chlitina.store.modules.cash.entity.StoreCardProduct;
import com.chlitina.store.modules.cash.entity.StoreCardTimes;
import com.chlitina.store.modules.cash.entity.StoreConsume;
import com.chlitina.store.modules.cash.entity.StoreConsumeDebt;
import com.chlitina.store.modules.cash.model.recharge.RechargeElementManager;
import com.chlitina.store.modules.cash.model.recharge.RehcargeHost;
import com.chlitina.store.modules.employee.entity.Employee;
import com.chlitina.store.modules.expert.entity.Care;
import com.chlitina.store.modules.sys.utils.StoreUtils;
import com.google.common.collect.Lists;

public class Member {
	private List<StoreCare> allcareList = null;
	private List<StoreCare> cardCareList = null;
	private RechargeElementManager rechargeEleMgr = new RechargeElementManager();
	private long cardPaymentId = 0;
	private MenuState menuState = new MenuState();
	private StoreConsumeDebt storeConsumeDebt;
	private float refundDebt;
	private float requiredRefundDebt;
	private List<StoreConsume> historyConsumes = null;
	// 正在进行的护理项目
	private List<StoreCare> inprogressCares = Lists.newArrayList();

	public long generateCardPaymentID() {
		return ++cardPaymentId;
	}

	private Employee employee;
	private Customer customer;
	private List<StoreConsumeDebt> storeConsumeDebts = new ArrayList<StoreConsumeDebt>();
	private List<CustomerEmployeeRelationship> customerEmployeeRelationships = new ArrayList<CustomerEmployeeRelationship>();
	private MemberShoppingCart shoppingCart = new MemberShoppingCart(this);
	private GiftCart giftCart = new GiftCart();
	/**
	 * 新开的所有卡信息
	 */
	private NewCards newCards = new NewCards(StoreUtils.getCardTemplates());
	/**
	 * 之前已经开过的卡信息
	 */
	private Cards currentCards = new Cards();
	private ShoppingPayment payment = new ShoppingPayment();
	private StoreProductCart productCart;
	// 可记录消费的卡
	private List<AllCardPayment> allCardPayments = new ArrayList<AllCardPayment>();
	// 目前可用的卡，当进行耗卡后，列表应及时被更新
	private List<AllCardPayment> avaibleAllCards = new ArrayList<AllCardPayment>();

	// 可记录消费的卡
	private List<ProductCardPayment> productCardPayments = new ArrayList<ProductCardPayment>();
	// 目前可用的卡，当进行耗卡后，列表应及时被更新
	private List<ProductCardPayment> avaibleProductCards = new ArrayList<ProductCardPayment>();

	// 可记录消费的卡
	private List<TimesCardPayment> timesCardPayments = new ArrayList<TimesCardPayment>();
	// 目前可用的卡，当进行耗卡后，列表应及时被更新
	private List<TimesCardPayment> avaibleTimesCards = new ArrayList<TimesCardPayment>();

	// 可记录消费的卡
	private List<DurationCardPayment> durationCardPayments = new ArrayList<DurationCardPayment>();
	// 目前可用的卡，当进行耗卡后，列表应及时被更新
	private List<DurationCardPayment> avaibleDurationCards = new ArrayList<DurationCardPayment>();

	public List<TimesCardPayment> getTimesCardPayments() {
		return timesCardPayments;
	}

	public List<TimesCardPayment> getAvaibleTimesCards() {
		return avaibleTimesCards;
	}

	public List<DurationCardPayment> getDurationCardPayments() {
		return durationCardPayments;
	}

	public List<DurationCardPayment> getAvaibleDurationCards() {
		return avaibleDurationCards;
	}

	private List<Employee> employees = null;

	/**
	 * create AllCardPayment list if it is valid card.
	 */
	public void initAvaibleAllCards() {
		allCardPayments.clear();
		avaibleAllCards.clear();
		List<StoreCardAll> allCards = currentCards.getAllCards();
		for (StoreCardAll storeCardAll : allCards) {
			if (storeCardAll.getMoney() > 0) {
				AllCardPayment allCardPayment = new AllCardPayment(
						storeCardAll, generateCardPaymentID());
				allCardPayments.add(allCardPayment);
				avaibleAllCards.add(allCardPayment);
			}
		}
	}

	public void updateAvailableAllCards() {
		if (avaibleAllCards.isEmpty()) {
			return;
		}
		List<AllCardPayment> toRemoved = new ArrayList<AllCardPayment>();
		for (AllCardPayment payment : avaibleAllCards) {
			if (payment.getMoney() >= payment.getCard().getMoney()) {
				toRemoved.add(payment);
			}
		}
		if (!toRemoved.isEmpty()) {
			avaibleAllCards.removeAll(toRemoved);
		}
	}

	/**
	 * create AllCardPayment list if it is valid card.
	 */
	public void initAvaibleProductCards() {
		productCardPayments.clear();
		avaibleProductCards.clear();
		List<StoreCardProduct> cards = currentCards.getProductCards();
		for (StoreCardProduct card : cards) {
			if (card.getMoney() > 0) {
				ProductCardPayment payment = new ProductCardPayment(card,
						generateCardPaymentID());
				productCardPayments.add(payment);
				avaibleProductCards.add(payment);
			}
		}
	}

	public void updateAvailableProductCards() {
		if (avaibleProductCards.isEmpty()) {
			return;
		}
		List<ProductCardPayment> toRemoved = new ArrayList<ProductCardPayment>();
		for (ProductCardPayment payment : avaibleProductCards) {
			if (payment.getMoney() >= payment.getCard().getMoney()) {
				toRemoved.add(payment);
			}
		}
		if (!toRemoved.isEmpty()) {
			avaibleProductCards.removeAll(toRemoved);
		}
	}

	public void initAvaibleTimesCards() {
		timesCardPayments.clear();
		avaibleTimesCards.clear();
		List<StoreCardTimes> timesCards = currentCards.getTimesCards();
		TimesCardPayment payment = null;
		for (StoreCardTimes card : timesCards) {
			if (card.getRemainTimes() > 0) {
				payment = new TimesCardPayment(card, generateCardPaymentID());
				timesCardPayments.add(payment);
				avaibleTimesCards.add(payment);
			}
		}
	}

	public void updateAvailableTimesCards() {
		if (avaibleTimesCards.isEmpty()) {
			return;
		}
		List<TimesCardPayment> toRemoved = new ArrayList<TimesCardPayment>();
		for (TimesCardPayment payment : avaibleTimesCards) {
			if (payment.getCurrentTimes() == 0) {
				toRemoved.add(payment);
			}
		}
		if (!toRemoved.isEmpty()) {
			avaibleTimesCards.removeAll(toRemoved);
		}
	}

	public void initAvaibleDurationCards() {
		durationCardPayments.clear();
		avaibleDurationCards.clear();
		List<StoreCardDuration> durationCards = currentCards.getDurationCards();
		DurationCardPayment payment = null;
		for (StoreCardDuration card : durationCards) {
			if (card.getEndTime().getTime() > System.currentTimeMillis()) {
				payment = new DurationCardPayment(card, generateCardPaymentID());
				durationCardPayments.add(payment);
				avaibleDurationCards.add(payment);
			}
		}
	}

	public void updateAvailableDurationCards() {
		if (avaibleDurationCards.isEmpty()) {
			return;
		}
		List<DurationCardPayment> toRemoved = new ArrayList<DurationCardPayment>();
		for (DurationCardPayment payment : avaibleDurationCards) {
			if (payment.getCard().getEndTime().getTime() < System
					.currentTimeMillis()) {
				toRemoved.add(payment);
			}
		}
		if (!toRemoved.isEmpty()) {
			avaibleDurationCards.removeAll(toRemoved);
		}
	}

	public boolean canFinish() {
		List<StoreProductCart> systemProducts = shoppingCart
				.getSystemProducts();
		for (StoreProductCart storeProductCart : systemProducts) {
			ProductPayment payment = storeProductCart.getPayment();
			if (payment == null) {
				return false;
			}
		}
		List<StoreProductCart> storeProductCarts = shoppingCart
				.getStoreProducts();
		for (StoreProductCart storeProductCart : storeProductCarts) {
			ProductPayment payment = storeProductCart.getPayment();
			if (payment == null) {
				return false;
			}
		}
		return true;
	}

	public void updateShoppingPayment() {
		float requiredCash = 0;

		// systemProduct
		for (StoreProductCart storeProductCart : shoppingCart
				.getSystemProducts()) {
			storeProductCart.updateDetails();
			if (storeProductCart.getPayment() == null) {
				System.err.println("ERROR PAYMENT");
				continue;
			}
			requiredCash += storeProductCart.getPayment().getCash();
		}
		// storeProduct
		for (StoreProductCart storeProductCart : shoppingCart
				.getStoreProducts()) {
			storeProductCart.updateDetails();
			if (storeProductCart.getPayment() == null) {
				System.err.println("ERROR PAYMENT");
				continue;
			}
			requiredCash += storeProductCart.getPayment().getCash();
		}

		// SolutionProduct
		for (StoreProductCart storeProductCart : shoppingCart
				.getSolutionProducts()) {
			storeProductCart.updateDetails();
			if (storeProductCart.getPayment() == null) {
				System.err.println("ERROR PAYMENT");
				continue;
			}
			requiredCash += storeProductCart.getPayment().getCash();
		}
		// systemCares
		for (StoreCareCart storeCareCart : shoppingCart.getSystemCares()) {
			if (storeCareCart.getPayment() == null) {
				System.err.println("ERROR PAYMENT");
				continue;
			}
			requiredCash += storeCareCart.getPayment().getCash();
		}
		// storeCares
		for (StoreCareCart storeCareCart : shoppingCart.getStoreCares()) {
			if (storeCareCart.getPayment() == null) {
				System.err.println("ERROR PAYMENT");
				continue;
			}
			requiredCash += storeCareCart.getPayment().getCash();
		}

		// storeCares
		for (StoreCareCart storeCareCart : shoppingCart.getSolutionCares()) {
			if (storeCareCart.getPayment() == null) {
				System.err.println("ERROR PAYMENT");
				continue;
			}
			requiredCash += storeCareCart.getPayment().getCash();
		}

		float total = 0;
		// debt
		total += refundDebt;
		// newCards
		NewCardsPayment cardsPayment = newCards.getCardsPayment();
		requiredCash += cardsPayment.getTotalCashCost();
		// recharge
		requiredCash += rechargeEleMgr.getPayment().getCashPay();

		total += requiredCash;
		System.err.println(total);
		payment.setTotal(total);
		payment.setDebt(total);
		payment.setPay(0);
	}

	public List<StoreCare> findAllCardCare() {
		List<StoreCare> cares = new ArrayList<StoreCare>();
		List<Long> added = new ArrayList<Long>();
		List<CardCart> durationCards = newCards.getDurationCards();
		for (CardCart cart : durationCards) {
			StoreCardDuration card = (StoreCardDuration) cart.getCard();
			StoreCardTemplateDuration template = card.getTemplate();
			StoreCare storeCare = template.getStoreCare();
			if (StoreCareUtils.getStatus(storeCare) == Care.FLAG_DISABLE) {
				continue;
			}
			if (!Utils.contains(added, storeCare.getId())) {
				cares.add(storeCare);
				added.add(template.getStoreCare().getId());
			}
		}
		List<CardCart> timesCards = newCards.getTimesCards();
		for (CardCart cart : timesCards) {
			StoreCardTimes card = (StoreCardTimes) cart.getCard();
			StoreCardTemplateTimes template = card.getTemplate();
			StoreCare storeCare = template.getStoreCare();
			if (StoreCareUtils.getStatus(storeCare) == Care.FLAG_DISABLE) {
				continue;
			}
			if (!Utils.contains(added, storeCare.getId())) {
				cares.add(template.getStoreCare());
				added.add(template.getStoreCare().getId());
			}
		}
		for (StoreCardDuration storeCardDuration : currentCards
				.getDurationCards()) {
			StoreCardTemplateDuration template = storeCardDuration
					.getTemplate();
			StoreCare storeCare = template.getStoreCare();
			if (StoreCareUtils.getStatus(storeCare) == Care.FLAG_DISABLE) {
				continue;
			}
			if (!Utils.contains(added, storeCare.getId())) {
				cares.add(template.getStoreCare());
				added.add(template.getStoreCare().getId());
			}
		}

		for (StoreCardTimes storeCardTimes : currentCards.getTimesCards()) {
			StoreCardTemplateTimes template = storeCardTimes.getTemplate();
			StoreCare storeCare = template.getStoreCare();
			if (StoreCareUtils.getStatus(storeCare) == Care.FLAG_DISABLE) {
				continue;
			}
			if (!Utils.contains(added, storeCare.getId())) {
				cares.add(template.getStoreCare());
				added.add(template.getStoreCare().getId());
			}
		}
		return cares;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public MemberShoppingCart getShoppingCart() {
		return shoppingCart;
	}

	public List<StoreConsumeDebt> getStoreConsumeDebts() {
		return storeConsumeDebts;
	}

	public void setStoreConsumeDebts(List<StoreConsumeDebt> storeConsumeDebts) {
		this.storeConsumeDebts = storeConsumeDebts;
	}

	public List<CustomerEmployeeRelationship> getCustomerEmployeeRelationships() {
		return customerEmployeeRelationships;
	}

	public void setCustomerEmployeeRelationships(
			List<CustomerEmployeeRelationship> customerEmployeeRelationships) {
		this.customerEmployeeRelationships = customerEmployeeRelationships;
	}

	public NewCards getNewCards() {
		return newCards;
	}

	public Cards getCurrentCards() {
		return currentCards;
	}

	public ShoppingPayment getPayment() {
		return payment;
	}

	public StoreProductCart getProductCart() {
		return productCart;
	}

	public void setProductCart(StoreProductCart productCart) {
		this.productCart = productCart;
	}

	public List<AllCardPayment> getAllCardPayments() {
		return allCardPayments;
	}

	public List<AllCardPayment> getAvaibleAllCards() {
		return avaibleAllCards;
	}

	public List<ProductCardPayment> getProductCardPayments() {
		return productCardPayments;
	}

	public List<ProductCardPayment> getAvaibleProductCards() {
		return avaibleProductCards;
	}

	public List<Employee> getEmployees() {
		return employees;
	}

	public void setEmployees(List<Employee> employees) {
		this.employees = employees;
	}

	public RechargeElementManager getRechargeEleMgr() {
		return rechargeEleMgr;
	}

	public List<StoreCare> getAllcareList() {
		return allcareList;
	}

	public void setAllcareList(List<StoreCare> allcareList) {
		this.allcareList = allcareList;
	}

	public List<StoreCare> getCardCareList() {
		return cardCareList;
	}

	public void setCardCareList(List<StoreCare> cardCareList) {
		this.cardCareList = cardCareList;
	}

	public void resetPayment() {
		// reset Card ALL
		for (AllCardPayment card : allCardPayments) {
			card.reset();
		}
		for (ProductCardPayment card : productCardPayments) {
			card.reset();
		}
		for (DurationCardPayment card : durationCardPayments) {
			card.reset();
		}
		for (TimesCardPayment card : timesCardPayments) {
			card.reset();
		}
	}

	/**
	 * auto calculate payment for ALL
	 */
	public void calculatePayment() {
		resetPayment();
		// repay debt

		// reCharge
		rechargeEleMgr.updatePayment();
		for (RehcargeHost rehchargeHost : rechargeEleMgr.getRechargedCardAll()) {
			rehchargeHost.recharge();
		}
		for (RehcargeHost rehchargeHost : rechargeEleMgr
				.getRechargedCardDuration()) {
			rehchargeHost.recharge();
		}
		for (RehcargeHost rehchargeHost : rechargeEleMgr
				.getRechargedCardProduct()) {
			rehchargeHost.recharge();
		}
		for (RehcargeHost rehchargeHost : rechargeEleMgr
				.getRechargedCardTimes()) {
			rehchargeHost.recharge();
		}

		// new Cards;
		newCards.getCardsPayment().calculatePayment(this);

		// BuyProducts,Do Cares
		shoppingCart.calculatePayment();

		giftCart.updateDesriptions();

		payment.updatePaymentForCares(shoppingCart);
		payment.updatePaymentForProduct(shoppingCart);

	}

	public CardPayment findNewCard(List<? extends CardPayment> payments,
			CardCart cart) {
		CardPayment cardPayment = null;
		for (CardPayment payment : payments) {
			if (payment.getCard().equals(cart.getCard())) {
				cardPayment = payment;
				break;
			}
		}
		return cardPayment;
	}

	public CardCart findById(List<CardCart> carts, int cartID) {
		for (CardCart cardCart : carts) {
			if (cardCart.getId() == cartID) {
				return cardCart;
			}
		}
		return null;
	}

	public boolean dropOpenCardAll(int cartID) {
		CardCart cart = findById(newCards.getAllCards(), cartID);
		if (cart == null) {
			return false;
		}
		return dropOpenCardAll(cart);

	}

	public boolean dropOpenCardProduct(int cartID) {
		CardCart cart = findById(newCards.getProductCards(), cartID);
		if (cart == null) {
			return false;
		}
		return dropOpenCardProduct(cart);

	}

	public boolean dropOpenCardTimes(int cartID) {
		CardCart cart = findById(newCards.getTimesCards(), cartID);
		if (cart == null) {
			return false;
		}
		return dropOpenCardTimes(cart);

	}

	public boolean dropOpenCardDuration(int cartID) {
		CardCart cart = findById(newCards.getDurationCards(), cartID);
		if (cart == null) {
			return false;
		}
		return dropOpenCardDuration(cart);

	}

	public boolean dropOpenCardAll(CardCart cart) {
		CardPayment cardPayment = findNewCard(allCardPayments, cart);
		allCardPayments.remove(cardPayment);
		avaibleAllCards.remove(cardPayment);
		newCards.getAllCards().remove(cart);
		rechargeEleMgr.removeCard(rechargeEleMgr.getRechargedCardAll(),
				rechargeEleMgr.getAllCards(), cardPayment);
		return true;
	}

	public boolean dropOpenCardProduct(CardCart cart) {
		CardPayment cardPayment = findNewCard(productCardPayments, cart);
		productCardPayments.remove(cardPayment);
		avaibleProductCards.remove(cardPayment);
		newCards.getProductCards().remove(cart);
		rechargeEleMgr.removeCard(rechargeEleMgr.getRechargedCardProduct(),
				rechargeEleMgr.getProductCards(), cardPayment);
		return true;
	}

	public boolean dropOpenCardTimes(CardCart cart) {
		CardPayment cardPayment = findNewCard(timesCardPayments, cart);
		timesCardPayments.remove(cardPayment);
		avaibleTimesCards.remove(cardPayment);
		newCards.getTimesCards().remove(cart);
		rechargeEleMgr.removeCard(rechargeEleMgr.getRechargedCardTimes(),
				rechargeEleMgr.getTimesCards(), cardPayment);
		return true;
	}

	public boolean dropOpenCardDuration(CardCart cart) {
		CardPayment cardPayment = findNewCard(durationCardPayments, cart);
		durationCardPayments.remove(cardPayment);
		avaibleDurationCards.remove(cardPayment);
		newCards.getDurationCards().remove(cart);
		rechargeEleMgr.removeCard(rechargeEleMgr.getRechargedCardDuration(),
				rechargeEleMgr.getDurationCards(), cardPayment);
		return true;
	}

	public void openNewCard(CardCart cart, StoreCardAll card) {
		AllCardPayment cardPayment = new AllCardPayment(card,
				generateCardPaymentID());
		allCardPayments.add(cardPayment);
		avaibleAllCards.add(cardPayment);
		newCards.getAllCards().add(cart);
		updateAvailableAllCards();
		rechargeEleMgr.add(rechargeEleMgr.getAllCards(), cardPayment);
	}

	public void openNewCard(CardCart cart, StoreCardProduct card) {
		ProductCardPayment cardPayment = new ProductCardPayment(card,
				generateCardPaymentID());
		productCardPayments.add(cardPayment);
		avaibleProductCards.add(cardPayment);
		newCards.getProductCards().add(cart);
		updateAvailableProductCards();
		rechargeEleMgr.add(rechargeEleMgr.getProductCards(), cardPayment);
	}

	public void openNewCard(CardCart cart, StoreCardDuration card) {
		DurationCardPayment cardPayment = new DurationCardPayment(card,
				generateCardPaymentID());
		durationCardPayments.add(cardPayment);
		avaibleDurationCards.add(cardPayment);
		newCards.getDurationCards().add(cart);
		updateAvailableDurationCards();
		rechargeEleMgr.add(rechargeEleMgr.getDurationCards(), cardPayment);
	}

	public void openNewCard(CardCart cart, StoreCardTimes card) {
		TimesCardPayment cardPayment = new TimesCardPayment(card,
				generateCardPaymentID());
		timesCardPayments.add(cardPayment);
		avaibleTimesCards.add(cardPayment);
		newCards.getTimesCards().add(cart);
		updateAvailableTimesCards();
		rechargeEleMgr.add(rechargeEleMgr.getTimesCards(), cardPayment);
	}

	public void updateRequiredRefundDebt() {
		requiredRefundDebt = 0;
		// update debt state
		List<StoreConsumeDebt> debts = getStoreConsumeDebts();
		for (StoreConsumeDebt debt : debts) {
			if (debt.getRefundConsume() == null) {
				storeConsumeDebt = debt;
				requiredRefundDebt += debt.getDebtMoney();
				break;
			}
		}
	}

	public void updateMenuState() {
		menuState.setHasDebt(getRefundDebt() != getRequiredRefundDebt());
		menuState.setHasNewCards(!newCards.isEmpty());
		menuState.setHasSolutionProduct(!shoppingCart.getSolutionProducts()
				.isEmpty());
		menuState
				.setHasSolutionCare(!shoppingCart.getSolutionCares().isEmpty());

		menuState.setHasProducts(!shoppingCart.getStoreProducts().isEmpty()
				|| !shoppingCart.getSystemProducts().isEmpty()
				|| menuState.isHasSolutionProduct());
		menuState.setHasCares(!shoppingCart.getStoreCares().isEmpty()
				|| !shoppingCart.getSystemCares().isEmpty()
				|| menuState.isHasSolutionCare());

		menuState.setHasRecharges(!rechargeEleMgr.isEmpty());

		menuState.setCanRecharge(false);
		if (!menuState.isHasDebt()) {
			// update can recharge state
			int cardSize = currentCards.getAllCards().size()
					+ currentCards.getDurationCards().size()
					+ currentCards.getProductCards().size()
					+ currentCards.getTimesCards().size();
			if (cardSize > 0) {
				menuState.setCanRecharge(true);
			} else {
				menuState.setCanRecharge(menuState.isHasNewCards());
			}
		}

		menuState.setHasGifts(!giftCart.getStoreProducts().isEmpty()
				|| !giftCart.getSystemProducts().isEmpty());
		menuState.setHasShoppingDetail(!menuState.isHasNewCards()
				&& !menuState.isHasGifts() && !menuState.isHasRecharges()
				&& !menuState.isHasProducts() && !menuState.isHasCares());
		menuState.setEmptyShopping(getRefundDebt() == 0
				&& menuState.isHasShoppingDetail());
	}

	public MenuState getMenuState() {
		return menuState;
	}

	public StoreConsumeDebt getStoreConsumeDebt() {
		return storeConsumeDebt;
	}

	public void setStoreConsumeDebt(StoreConsumeDebt storeConsumeDebt) {
		this.storeConsumeDebt = storeConsumeDebt;
	}

	public float getRefundDebt() {
		return refundDebt;
	}

	public void setRefundDebt(float refundDebt) {
		this.refundDebt = refundDebt;
	}

	public float getRequiredRefundDebt() {
		return requiredRefundDebt;
	}

	public void setRequiredRefundDebt(float requiredRefundDebt) {
		this.requiredRefundDebt = requiredRefundDebt;
	}

	public void init() {
		initAvaibleAllCards();
		initAvaibleProductCards();
		initAvaibleTimesCards();
		initAvaibleDurationCards();
		updateRequiredRefundDebt();
		rechargeEleMgr.init(this);
	}

	public boolean doRepayDebtOnly() {
		if (menuState.isHasCares() || menuState.isHasGifts()
				|| menuState.isHasNewCards() || menuState.isHasRecharges()
				|| menuState.isHasProducts()) {
			return false;
		}

		return getRefundDebt() > 0;
	}

	public List<StoreConsume> getHistoryConsumes() {
		return historyConsumes;
	}

	public void setHistoryConsumes(List<StoreConsume> historyConsumes) {
		this.historyConsumes = historyConsumes;
	}

	public GiftCart getGiftCart() {
		return giftCart;
	}

	public void setGiftCart(GiftCart giftCart) {
		this.giftCart = giftCart;
	}

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public List<StoreCare> getInprogressCares() {
		return inprogressCares;
	}

	public void setInprogressCares(List<StoreCare> inprogressCares) {
		this.inprogressCares = inprogressCares;
	}

	public void addOldCard(StoreCardDuration card) {
		List<StoreCardDuration> durationCards = currentCards.getDurationCards();
		durationCards.add(card);
		if (card.getEndTime().getTime() > System.currentTimeMillis()) {
			DurationCardPayment payment = new DurationCardPayment(card,
					generateCardPaymentID());
			durationCardPayments.add(payment);
			avaibleDurationCards.add(payment);
		}

	}

	public void addOldCard(StoreCardAll card) {
		List<StoreCardAll> allCards = currentCards.getAllCards();
		allCards.add(card);
		if (card.getMoney() > 0) {
			AllCardPayment allCardPayment = new AllCardPayment(card,
					generateCardPaymentID());
			allCardPayments.add(allCardPayment);
			avaibleAllCards.add(allCardPayment);
		}
	}

	public void addOldCard(StoreCardTimes card) {
		List<StoreCardTimes> timesCards = currentCards.getTimesCards();
		timesCards.add(card);
		if (card.getRemainTimes() > 0) {
			TimesCardPayment payment = new TimesCardPayment(card,
					generateCardPaymentID());
			timesCardPayments.add(payment);
			avaibleTimesCards.add(payment);
		}

	}

	public void addOldCard(StoreCardProduct card) {
		List<StoreCardProduct> productCards = currentCards.getProductCards();
		productCards.add(card);
		if (card.getMoney() > 0) {
			ProductCardPayment payment = new ProductCardPayment(card,
					generateCardPaymentID());
			productCardPayments.add(payment);
			avaibleProductCards.add(payment);
		}

	}
}
